home *** CD-ROM | disk | FTP | other *** search
/ Power Tools for Macintosh / Power Tools for Macintosh (SoftBit)(1992).iso / Stacks / *F-I / HyperCard Utilities / Videodisc⁄Drivers ƒ / PioneerLDV6000.p < prev    next >
Encoding:
Text File  |  1987-01-31  |  6.2 KB  |  269 lines  |  [TEXT/MPS ]

  1. {$R-}
  2. {$D+}
  3. (*
  4.     Pioneer-LD-V6000 -- a WildCard user-defined command to drive a laser disc player.
  5.  
  6.     To compile and link this file using Macintosh Programmer's Workshop,
  7.  
  8.     pascal PioneerLDV6000.p
  9.     link -o WildCommands -sn Main=PioneerLDV6000 -sn STDIO=PioneerLDV6000 ∂
  10.          -sn INTENV=PioneerLDV6000 -rt WCMD=4 ∂
  11.          PioneerLDV6000.p.o {MPW}libraries:interface.o
  12.  
  13.     then use ResEdit to copy the resulting WCMD from WildCommands
  14.     and paste it into WildCard, the Home stack, or your own stack.
  15.     (WCMD=1 Panasonic, =2 Hitachi, =3 Phillips, =4 PioneerLDV6000)
  16. *)
  17.  
  18. UNIT DummyUnit;
  19.  
  20. INTERFACE
  21.  
  22.    USES MemTypes, QuickDraw, OsIntf;
  23.     
  24. IMPLEMENTATION
  25.  
  26. PROCEDURE Pioneer(commandPtr: Ptr);                                        FORWARD;
  27.  
  28.    PROCEDURE EntryPoint(arg: Ptr);
  29.    { entry point cannot have local procs, but forward routines can }
  30.    BEGIN
  31.      Pioneer(arg);
  32.    END;
  33.  
  34.    PROCEDURE Pioneer(commandPtr: Ptr);
  35.    VAR reverseFlag, offFlag, tillFlag: BOOLEAN;
  36.        message: Str255;
  37.        refNum: INTEGER;
  38.        err: INTEGER;
  39.             
  40.      PROCEDURE OpenSerial;
  41.      VAR handShake: SerShk;
  42.          baudRate: INTEGER;
  43.      BEGIN
  44.        baudRate := 9600;
  45.        { for now, use modem port so we don't mess with AppleTalk }
  46.        err := FSOpen('.AOUT',0,refNum);
  47.        IF err = 0 THEN 
  48.          BEGIN
  49.            WITH handShake DO
  50.              BEGIN
  51.                fXon := 1;
  52.                fCTS := 1;
  53.                xon  := CHR(17);
  54.                xoff := CHR(19);
  55.                errs := 0;
  56.                evts := 0;
  57.                fInx := 0;
  58.              END;
  59.            err := SerHShake(refNum,handShake);
  60.            IF err = 0 THEN 
  61.              err := Control(refNum,13,@baudRate);
  62.          END;
  63.      END;
  64.      
  65.      
  66.      PROCEDURE CloseSerial;
  67.      BEGIN
  68.        err := FSClose(refNum);
  69.      END;
  70.      
  71.      
  72.      PROCEDURE SendCommand(cmd: Str255);
  73.      VAR count: LongInt;
  74.      BEGIN
  75.        count := Length(cmd);
  76.        err := FSWrite(refNum, count, Pointer(Ord(@cmd)+1));
  77.      END;
  78.      
  79.      FUNCTION Concat(str1, str2, str3: Str255): Str255;
  80.      VAR result: Str255;
  81.          resultLen: INTEGER;
  82.          charNum: INTEGER;
  83.      BEGIN
  84.        result := '';
  85.        resultLen := 0;
  86.        FOR charNum := 1 TO Length(str1) DO
  87.          BEGIN
  88.            resultLen := resultLen + 1;
  89.            result[resultLen] := str1[charNum];
  90.          END;
  91.        FOR charNum := 1 TO Length(str2) DO
  92.          BEGIN
  93.            resultLen := resultLen + 1;
  94.            result[resultLen] := str2[charNum];
  95.          END;
  96.        FOR charNum := 1 TO Length(str3) DO
  97.          BEGIN
  98.            resultLen := resultLen + 1;
  99.            result[resultLen] := str3[charNum];
  100.          END;
  101.       result[0] := CHR(resultLen);
  102.       Concat := result;
  103.      END;
  104.      
  105.      
  106.      PROCEDURE GetMessage;     
  107.      VAR charNum: INTEGER;
  108.          msgChar: CHAR;
  109.      BEGIN
  110.        { skip command name }
  111.        WHILE (commandPtr^ <> 0) AND (commandPtr^ <> 13) AND (CHR(commandPtr^) <> ' ') DO
  112.          commandPtr := Pointer(Ord(commandPtr)+1);
  113.          
  114.        { skip following white space }
  115.        WHILE CHR(commandPtr^) = ' ' DO 
  116.          commandPtr := Pointer(Ord(commandPtr)+1);
  117.          
  118.        { extract the rest into a Str255 }
  119.        charNum := 0;
  120.        WHILE (commandPtr^ <> 0) AND (charNum < 255) DO
  121.          BEGIN
  122.            msgChar := CHR(commandPtr^);
  123.            commandPtr := Pointer(Ord(commandPtr)+1);
  124.            charNum := charNum + 1;
  125.            IF (ORD(msgChar) >= ORD('A')) AND (ORD(msgChar) <= ORD('Z')) THEN
  126.              message[charNum] := CHR(ORD('a') + (ORD(msgChar) - ORD('A')))
  127.            ELSE message[charNum] := msgChar;
  128.          END;
  129.        message[0] := CHR(charNum);
  130.      END;
  131.      
  132.        
  133.      FUNCTION Contains(target: Str255): BOOLEAN;
  134.      VAR offset: INTEGER;     
  135.      
  136.        FUNCTION Match: BOOLEAN;
  137.        VAR index: INTEGER;
  138.        BEGIN
  139.          Match := TRUE;
  140.          FOR index := 1 TO Length(target) DO
  141.            IF offset + index > Length(message) THEN 
  142.              BEGIN
  143.                Match := FALSE;  { ran off the end }
  144.                EXIT(Match);
  145.              END
  146.            ELSE IF target[index] <> message[offset+index] THEN
  147.              BEGIN
  148.                Match := FALSE;  { hit a wrong char }
  149.                EXIT(Match);
  150.              END;
  151.        END;
  152.        
  153.      BEGIN
  154.        Contains := FALSE;
  155.        FOR offset := 0 TO Length(message) - 1 DO
  156.          IF Match THEN
  157.            BEGIN
  158.              Contains := TRUE;
  159.              EXIT(Contains);
  160.            END;
  161.      END;
  162.      
  163.      
  164.      FUNCTION GetDigit(digit: CHAR): Str255;
  165.      BEGIN
  166.        CASE digit OF
  167.          '0': GetDigit := '3F';
  168.          '1': GetDigit := '0F';
  169.          '2': GetDigit := '8F';
  170.          '3': GetDigit := '4F';
  171.          '4': GetDigit := '2F';
  172.          '5': GetDigit := 'AF';
  173.          '6': GetDigit := '6F';
  174.          '7': GetDigit := '1F';
  175.          '8': GetDigit := '9F';
  176.          '9': GetDigit := '5F';
  177.        END;
  178.      END;
  179.   
  180.   
  181.      FUNCTION GetInteger: Str255;
  182.      { get an integer in Pioneer format }
  183.      VAR digitLoc, charVal: INTEGER;
  184.          intStr: Str255;       
  185.      BEGIN
  186.        intStr := '';
  187.        FOR digitLoc := 1 TO Length(message) DO
  188.          BEGIN
  189.            charVal := ORD(message[digitLoc]);
  190.            IF (charVal >= ORD('0')) AND (charVal <= ORD('9')) THEN
  191.              intStr := Concat(intStr, GetDigit(message[digitLoc]), '');
  192.          END;
  193.        GetInteger := intStr;
  194.      END;
  195.  
  196.    BEGIN
  197.      OpenSerial;
  198.      IF err <> 0 THEN 
  199.        BEGIN
  200.          SysBeep(1);
  201.          EXIT(Pioneer);
  202.        END;
  203.      
  204.      GetMessage;
  205.      
  206.      { set flags }
  207.      reverseFlag := Contains('rev');
  208.      offFlag := Contains('off');
  209.      tillFlag := Contains('till');
  210.      
  211.      IF Contains('stop') THEN SendCommand('@FB')
  212.      ELSE IF Contains('eject') THEN SendCommand('@F9')
  213.      ELSE IF Contains('search') THEN SendCommand(Concat('@', GetInteger, 'F7'))
  214.      ELSE IF Contains('step') THEN
  215.        BEGIN
  216.          IF reverseFlag THEN SendCommand('@FE')
  217.          ELSE SendCommand('@F6')
  218.        END
  219.      ELSE IF Contains('play') THEN
  220.        BEGIN
  221.          IF tillFlag THEN SendCommand(Concat('@', GetInteger, 'F3'))
  222.          ELSE IF reverseFlag THEN SendCommand('@0FECFA')
  223.          ELSE SendCommand('@FD')
  224.        END
  225.      ELSE IF Contains('slow') THEN
  226.        BEGIN
  227.          IF reverseFlag THEN SendCommand('@4FEDFA')
  228.          ELSE SendCommand('@4FEDF2')
  229.        END
  230.      ELSE IF Contains('fast') THEN
  231.        BEGIN
  232.          IF reverseFlag THEN SendCommand('@4FECFA')
  233.          ELSE SendCommand('@4FECF2')
  234.        END
  235.      ELSE IF Contains('scan') THEN
  236.        BEGIN
  237.          IF reverseFlag THEN SendCommand('@4FECFA')
  238.          ELSE SendCommand('@4FECF2')
  239.        END
  240.      ELSE IF Contains('picture') THEN
  241.        BEGIN
  242.          IF offFlag THEN SendCommand('@1C')
  243.          ELSE SendCommand('@1B')
  244.        END
  245.      ELSE IF Contains('frame') THEN
  246.        BEGIN
  247.          IF offFlag THEN SendCommand('@3FF1')
  248.          ELSE SendCommand('@0FF1')
  249.        END
  250.      ELSE IF Contains('sound') THEN 
  251.        BEGIN
  252.          IF Contains('1') THEN
  253.            IF offFlag THEN SendCommand('@3FF4')
  254.            ELSE SendCommand('@0FF4')
  255.          ELSE IF Contains('2') THEN
  256.            IF offFlag THEN SendCommand('@3FFC')
  257.            ELSE SendCommand('@0FFC')
  258.          ELSE SysBeep(1);
  259.        END
  260.      ELSE IF NOT Contains('init') THEN { init does nothing for this player }
  261.         SysBeep(1); { unknown command }
  262.      CloseSerial;
  263.    END;   
  264.  
  265. END.
  266.  
  267.  
  268.  
  269.